﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>{{ title }}</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <style>
        #results {
            padding-top: 25px;
            padding-bottom: 25px;
        }

        #body {
            background-image: url(../static/home_images/ai-background_62139.png);
            background-size: cover;
        }
        #return-home.btn,
        #upload-button.btn {
            outline-color: black;
            color: white;
            background-color: rgb(0, 110, 150);
        }
        #return-home.btn:hover,
        #upload-button.btn:hover {
            background-color: rgb(0, 110, 230);
        }
        .progress-bar{
            background-color: rgb(0, 110, 150);
            color: white;
        }
        .progress-title{
            line-height: 14px
        }
        #face-picker.check::after{
            color: rgb(0, 110, 150);
        }
        #face-picker.check::before{
            border: 5px solid rgb(0, 110, 150);
        }
    </style>
</head>
<body>
    <header>
        <div class="collapse bg-dark" id="navbarHeader">
            <div class="container">
                <div class="row">
                    <div class="col-sm-8 col-md-7 py-4">
                        <h4 class="text-white">About</h4>
                        <p class="text-white">
                            I am Daniel Silva, a Computer Science and Statistics student at the University of Central Florida.
                            I'll write more about myself later.
                        </p>
                    </div>
                    <div class="col-sm-4 offset-md-1 py-4">
                        <h4 class="text-white">Contact</h4>
                        <ul class="list-unstyled">
                            <li><a href="#" class="text-white">Visit my portfolio</a></li>
                            <li><a href="https://www.linkedin.com/in/danielsilva98" class="text-white">Connect with me on LinkedIn</a></li>
                            <li><a href="danielzgsilva@knights.ucf.edu" class="text-white">Email me</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="navbar navbar-dark bg-dark box-shadow">
            <div class="container d-flex justify-content-between">
                <a href="#" class="navbar-brand d-flex align-items-left">
                    <strong>Daniel Silva's Facial Classifier</strong>
                </a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarHeader" aria-controls="navbarHeader" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
            </div>
        </div>
    </header>

    <main role="main">
        {% if num_faces == 0 %}
            <div class="jumbotron jumbotron-fluid text-center" style="background-color: white" id="results">
                <h1>Classification Results</h1>
                <p class="lead">
                    Oops! We were not able to detect any faces in your image.<br />
                    Please select a different image for classification.
                </p><br>
                <form id="upload-form" action="{{ url_for('upload') }}" method="POST" enctype="multipart/form-data">
                    <p>
                        <input id="file-picker" class="btn btn-outline-secondary" type="file" name="file" accept="image/*" single />
                        <input type="submit" class="btn" value="Try again with a different picture!" id="upload-button" />
                    </p>
                </form>
            </div>
            <div class="container-fluid text-center" id="body"><br>
                <div class="row justify-content-center">
                    <div class="card border-secondary mb-4 box-shadow">
                        <img src="{{url_for('send_image', filename=image_name)}}"><br>
                        <div class="card-body">
                            <p class="card-text"></p>
                            <div class="d-flex justify-content-between align-items-center">
                                <div class="btn-group">
                                    <form id="return-home" action="{{ url_for('index') }}">
                                        <input type="submit" class="btn btn-sm" value="Return home" id="return-home">
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        {% endif %}


        {% if num_faces == 1 %}
            <div class="jumbotron jumbotron-fluid text-center" style="background-color: white" id="results">
                <h1>Classification Results</h1>
                <p class="lead">We found 1 face in your image!</p><br>
                <form id="upload-form" action="{{ url_for('upload') }}" method="POST" enctype="multipart/form-data">
                    <p>
                        <input id="file-picker" class="btn btn-outline-secondary" type="file" name="file" accept="image/*" single />
                        <input type="submit" class="btn" value="Try again with a different picture!" id="upload-button" />
                    </p>
                </form>
            </div>
            <div class="container-fluid text-center" id="body"><br />
                <div class="row justify-content-center">
                    <div class="card border-secondary mb-4 box-shadow">
                        <img src="{{url_for('send_image', filename=image_name)}}">
                        <div class="card-body">
                            <img src=" {{url_for('send_face', facename=face_names[0])}}" class="rounded"><br><br>
                            <div class="container">
                                <div class="row align-self-center">
                                  <div class="col-md-6">
                                        <span class="text-nowrap">
                                            <p class="progress-title">{{ predictions[1][0][0] }}</p>
                                        </span>
                                  </div>
                                  <div class="col-md-6">
                                    <div class="progress">
                                        <div class="progress-bar" role="progressbar" style="width: {{ predictions[1][0][1] }}%">
                                            {{ predictions[1][0][1] }}%</div>
                                    </div>
                                  </div>
                                </div>
                                <div class="row align-self-center">
                                  <div class="col-md-6">
                                    <span class="text-nowrap">
                                        <p class="progress-title">{{ predictions[1][1][0] }}</p>
                                    </span>
                                  </div>
                                  <div class="col-md-6">
                                    <div class="progress">
                                      <div class="progress-bar" role="progressbar" style="width: {{ predictions[1][1][1] }}%">
                                        {{ predictions[1][1][1] }}%</div>
                                    </div>
                                  </div>
                                </div>
                                <div class="row align-self-center">
                                    <div class="col-md-6">
                                        <span class="text-nowrap">
                                            <p class="progress-title">{{ predictions[1][2][0] }}</p>
                                        </span>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="progress">
                                        <div class="progress-bar" role="progressbar" style="width: {{ predictions[1][2][1] }}%">
                                            {{ predictions[1][2][1] }}%</div>
                                        </div>
                                    </div>
                                </div>
                            </div><br>
                            <div class="d-flex justify-content-between align-items-center">
                                <div class="btn-group">
                                    <form id="return-home" action="{{ url_for('index') }}">
                                        <input type="submit" class="btn btn-sm" value="Return home" id="return-home">
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        {% endif %}

        {% if num_faces > 1 %}
            <div class="jumbotron jumbotron-fluid text-center" style="background-color: white" id="results">
                <h1>Classification Results</h1>
                <p class="lead">We found {{ num_faces }} faces in your image!</p><br />
                <form id="upload-form" action="{{ url_for('upload') }}" method="POST" enctype="multipart/form-data">
                    <p>
                        <input id="file-picker" class="btn btn-outline-secondary" type="file" name="file" accept="image/*" single />
                        <input type="submit" class="btn" value="Try again with a different picture!" id="upload-button" />
                    </p>
                </form>
            </div>
            <div class="container-fluid text-center" id="body"><br />
                <div class="row justify-content-center">
                    <div class="card border-secondary mb-4 box-shadow">
                        <img src="{{ url_for('send_image', filename=image_name) }}"><br>
                        <div class="row justify-content-center">
                            {% for face_name in face_names %}
                                {% if loop.index == 1 %}
                                <div class="form-check form-check-inline">
                                    <input class="form-check-input" type="radio" name="inlineRadioOptions" id="{{ loop.index }}" value="{{ loop.index }}" onchange='pickFace({{ loop.index|tojson }})' checked>
                                    <label class="form-check-label" for="{{ loop.index }}">{{ loop.index }}</label>
                                </div>
                                {% else %}
                                <div class="form-check form-check-inline">
                                    <input class="form-check-input" type="radio" name="inlineRadioOptions" id="face-picker" value="{{ loop.index }}" onchange='pickFace({{ loop.index|tojson }})'>
                                    <label class="form-check-label" for="{{ loop.index }}">{{ loop.index }}</label>
                                </div>
                                {% endif %}
                            {% endfor %}
                        </div>
                        <div class="card-body">
                            <img src="{{url_for('send_face', facename=face_names[0])}}" id="face" class="rounded"><br><br>
                            <div class="container">
                                <div class="row align-self-center">
                                  <div class="col-md-6">
                                    <span class="text-nowrap">
                                        <p class="progress-title" id="age">{{ predictions[1][0][0] }}</p>
                                        </span>
                                  </div>
                                  <div class="col-md-6">
                                    <div class="progress">
                                        <div class="progress-bar" id="age-confidence" style="width: {{ predictions[1][0][1] }}%">
                                            {{ predictions[1][0][1] }}%</div>
                                    </div>
                                  </div>
                                </div>
                                <div class="row align-self-center">
                                  <div class="col-md-6">
                                    <span class="text-nowrap">
                                        <p class="progress-title" id="gender">{{ predictions[1][1][0] }}</p>
                                    </span>
                                  </div>
                                  <div class="col-md-6">
                                    <div class="progress">
                                      <div class="progress-bar" id="gender-confidence" style="width: {{ predictions[1][1][1] }}%">
                                        {{ predictions[1][1][1] }}%</div>
                                    </div>
                                  </div>
                                </div>
                                <div class="row align-self-center">
                                    <div class="col-md-6">
                                        <span class="text-nowrap">
                                            <p class="progress-title" id="race">{{ predictions[1][2][0] }}</p>
                                        </span>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="progress">
                                        <div class="progress-bar" id="race-confidence" style="width: {{ predictions[1][2][1] }}%">
                                            {{ predictions[1][2][1] }}%</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <br>
                            <div class="d-flex justify-content-between align-items-center">
                                <div class="btn-group">
                                    <form id="return-home" action="{{ url_for('index') }}">
                                        <input type="submit" class="btn btn-sm" value="Return home" id="return-home">
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        {% endif %}
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    </main>

    <footer class="text-muted">
        <div style="background-color: white">
            <div class="container">
                <br />
                <p class="float-right">
                    <a href="#">Back to top</a>
                </p>
                <p class="float-left">Daniel Silva's Facial Classifier</p>
            </div>
        </div>
    </footer>
</body>
</html>
<script>
    $("#file-picker").change(function () {
        var input = document.getElementById('file-picker');
        for (var i = 0; i < input.files.length; i++) {
            var ext = input.files[i].name.substring(input.files[i].name.lastIndexOf('.') + 1).toLowerCase()
            if ((ext == 'jpg') || (ext == 'png') || (ext == 'jpeg')) {
                $("#msg").text("Your file is supported.")
            }
            else {
                $("#msg").text("File was NOT supported. Please upload either a JPG or PNG file.")
                document.getElementById("file-picker").value = "";
            }
        }
    });

    function pickFace(face_num) {
        const js_predictions = {{ predictions|tojson }};
        const js_face_names = {{ face_names|tojson }}
        
        var image = document.getElementById("face");
        var face = face_num - 1
        image.src = "{{ url_for('send_face', facename=temp) }}" + js_face_names[face]
        
        var age = document.getElementById("age");
        var gender = document.getElementById("gender");
        var race = document.getElementById("race");

        age.innerHTML = js_predictions[face_num][0][0]
        gender.innerHTML = js_predictions[face_num][1][0]
        race.innerHTML = js_predictions[face_num][2][0]

        var age_confidence = document.getElementById("age-confidence");
        var gender_confidence = document.getElementById("gender-confidence");
        var race_confidence = document.getElementById("race-confidence");

        age_confidence.innerHTML = js_predictions[face_num][0][1] + '%'
        gender_confidence.innerHTML = js_predictions[face_num][1][1] + '%'
        race_confidence.innerHTML = js_predictions[face_num][2][1] + '%'

        age_confidence.style.width = js_predictions[face_num][0][1] + '%'
        gender_confidence.style.width = js_predictions[face_num][1][1] + '%'
        race_confidence.style.width = js_predictions[face_num][2][1] + '%' 
    }
</script>

